﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Web.Library.DomainObject.SQLServer;
using Web.Library.Facade.SQLServer;
using System.Configuration;
using Web.Support;

public partial class Form_sysMenuForm : System.Web.UI.Page
{
    private SysMenuFacade Facade = new SysMenuFacade(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
    private int id = -1;
    //private SysApplicationFacade Facade = new SysApplicationFacade(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {

        }
    }

    protected override void OnLoad(EventArgs e)
    {
        try
        {
            if (Request.Params["id"] != null)
            {
                id = Convert.ToInt32(Request.Params["id"]);
            }

            List<SysMenu> list = new List<SysMenu>();
            list = Facade.GetList();
            ddlParent.Items.Clear();
            list.ForEach(delegate(SysMenu menu)
            {
                ddlParent.Items.Add(new ListItem(menu.Title, menu.MenuID.ToString()));
            });
            ddlParent.Items.Insert(0, new ListItem("--select parent---", "0"));


            if (!Page.IsPostBack)
            {
                if (id > 0) // Edit an existing item
                {
                    SysMenu obj = Facade.GetById(id);
                    if (obj != null)
                    {
                        hfID.Value = id.ToString();
                        txtTitle.Text = obj.Title;
                        txtSort.Text = obj.Sort.ToString();
                        txtUrl.Text = obj.Url;
                        ddlParent.Items.FindByValue(obj.ParentID.ToString()).Selected = true;
                        //ddlRowStatus.SelectedValue = Competency.RowStatus == true ? "1" : "0";
                        //ddlGroup.Items.FindByValue(Competency.GroupCompetency.ToString()).Selected = true;
                    }
                }
                //GetPrivilege();
            }
        }
        catch(Exception ex)
        {
            Logger.Debug("OnLoad on sysMenuForm.aspx", ex);
        }

    }
}